package com.dai.yygh.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dai.yygh.model.hosp.HospitalSet;
import com.dai.yygh.mapper.HospitalSetMapper;
import com.dai.yygh.service.HospitalSetService;
import com.dai.yygh.vo.hosp.HospitalQueryVo;
import com.dai.yygh.vo.hosp.HospitalSetQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HospitalSetServiceImpl implements HospitalSetService {
    @Autowired
    private HospitalSetMapper hospitalSetMapper;

    @Override
    public List<HospitalSet> findAll() {
        return hospitalSetMapper.selectList(null);
    }

    @Override
    public boolean deleteremoveHospSetById(Long id) {
        int i = hospitalSetMapper.deleteById(id);
        if(i==1) return true;
        else return false;
    }

    @Override
    public List<HospitalSet> findPageHospSet(Page<HospitalSet> page, HospitalSetQueryVo hospitalSetQueryVo) {
        LambdaQueryWrapper<HospitalSet> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.like(HospitalSet::getHosname,hospitalSetQueryVo.getHosname());
        queryWrapper.eq(HospitalSet::getHoscode,hospitalSetQueryVo.getHoscode());
        IPage<HospitalSet> iPage=hospitalSetMapper.selectPage(page,queryWrapper);
        List<HospitalSet> records = iPage.getRecords();
        return records;
    }

    @Override
    public boolean saveHospitalSet(HospitalSet hospitalSet) {
        int insert = hospitalSetMapper.insert(hospitalSet);
        if(insert==1) return true;
        else  return false;
    }

    @Override
    public HospitalSet getHospSet(Long id) {
        HospitalSet hospitalSet = hospitalSetMapper.selectById(id);
        return hospitalSet;
    }

    @Override
    public boolean updateHospitalSet(HospitalSet hospitalSet) {

        int i = hospitalSetMapper.updateById(hospitalSet);
        if(i==1) return true;
        else  return false;
    }

    @Override
    public Boolean batchRemoveHospitalSet(List<Long> idlist) {
        int i = hospitalSetMapper.deleteBatchIds(idlist);
        if(i==0) return false;
        else return true;

    }

    @Override
    public String getSignKey(String hoscode) {
        LambdaQueryWrapper<HospitalSet> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HospitalSet::getHoscode,hoscode);
        HospitalSet hospitalSet = hospitalSetMapper.selectOne(queryWrapper);
        return hospitalSet.getSignKey();
    }

}
